﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Collections;

namespace AcesHigh
{
    class Deck
    {
        private int cardIndex;
        private Card[] cards;
        private static Random rng = new Random();
       
        public Deck(String imagePath)
        {
            initCards();
            cardIndex = 0;
        }

        public bool IsEmpty
        {
            get{ return this.cardIndex == cards.Length; }
        }

        private void initCards() 
        {
            cards = new Card[52];
            Suit suit = Suit.Clubs;
            Rank rank;

            int index = 0;
            for (int i = 0; i < 4; i++)
            {
                rank = Rank.Two;
                for (int j = 2; j < 15; j++)
                {
                    cards[index] = new Card(rank, suit);
                    rank++;
                    index++;
                }
                suit++;
            }
            ShuffleCards();
        }

        private void ShuffleCards()
        {
            for (int i=cards.Length-1; i > 0; i--)
            {
                int swapIndex = rng.Next(i+1);
                if (swapIndex != i)
                {
                    Card tmp = cards[swapIndex];
                    cards[swapIndex] = cards[i];
                    cards[i]= tmp;
                }
            }
        }

        /*
         * 
         */
        public Card dealCard()
        {
            if (cardIndex < cards.Length)
            {
                Card c = cards[cardIndex];
                cardIndex++;
                return c;
            }
            return null;
        }
    }
}
